Skip to main content

Margin Trading

Margin trading refers to using borrowed funds to pay for a trade. Margin trading allows traders to open a position in the market without paying the entire price up-front.

Before delving deeper into Margin trading, below are some terms related to Margin trading you should be familiar with.

TermExplanation
LeverageLeverage refers to the use of borrowed funds to pay for a trade.For example, if a trader wishes to buy a $1000 token for 5x leverage, they will only have to pay $200 upfront, and the exchange or broker will pay the remaining amount.
EquityThe value of an account based on the current market price minus the borrowed amount is known as equity.
MarginBecause of the real-time fluctuation in the Crypto market, the equity level will also fluctuate. If the equity level drops below a certain level, the trader may have to sell some or all their positions or add more funds to their account.
Margin CallIf the equity level drops below the set threshold level the trader gets a notification known as a Margin call.
CollateralThe assets that are available in the user’s account are used as collateral.
LiquidationIf the trader fails to meet a margin call the exchange can sell its assets to pay this loan. This process is known as liquidation.

Let us try to understand these concepts more with an example.

Assume we bought a crypto token worth $1000, with 5x leverage. In this case, you will be paying $200 and the exchange or broker will pay $800.

SpotMargin
Amount that the trader Invested($)200200
Borrowed Amount($)-800
Total Amount Invested($)200200+800 = 1000
Increase of 10%2201100
Profit($)220 - 200 = $201100 - 800 - 200 = $100

In the case above, you will make a profit five times Spot trading because you have invested 5x the amount up-front.

But, Margin trading is a two-edged sword. So, instead of increasing by 10%, if the token's value drops by 10%, you will lose 5x the amount.

For example,

SpotMargin
Amount that the trader Invested($)200200
Borrowed Amount($)-800
Total Amount Invested($)200200+800 = 1000
Decrease of 10%180900
Loss($)180 - 200 = - $20900 - 800 - 200 = - $100

First Margin Order on CoinDCX API

To place a margin order, follow these steps:

  1. Use the following endpoint to place your margin order.
https://api.coindcx.com/exchange/v1/margin/create
  1. Specify the following details in the body of your code:
ParameterRequiredDescription
marketYesIndicates the pair for which the order is being placed.
QuantityYesThe quantity of the asset to be traded.
priceYesPrice of the asset per unit.
leverageNoRefers to the capital borrowed from the exchange or broker to increase the returns.
sideYesIndicates the side for which you are placing the order. Acceptable values are:
  • Buy
  • Sell
stop_priceNoIndicates the price at which the order stops.
order_typeYesIndicates the order type. The following order types can be used:
  • market_order
  • limit_order
  • stop_limit
  • take_profit
trailing_slNoIndicates an order placed with trailing stop-loss.
target_priceNoIndicates the price at which you wish to either buy, sell, or close the order.
ecodeYesIndicates the exchange code in which the order will be placed.
timestampYesIndicates the timestamp at which the request was generated.
  1. Once the order has been placed, you will receive a confirmation in the following format.
[
{
"id": "30b5002f-d9c1-413d-8a8d-0fd32b054c9c",
"side": "sell",
"status": "init",
"market": "XRPBTC",
"order_type": "limit_order",
"trailing_sl": false,
"trail_percent": null,
"avg_entry": 0,
"avg_exit": 0,
"fee": 0.02,
"entry_fee": 0,
"exit_fee": 0,
"active_pos": 0,
"exit_pos": 0,
"total_pos": 0,
"quantity": 200,
"price": 0.000026,
"sl_price": 0.00005005,
"target_price": 0,
"stop_price": 0,
"pnl": 0,
"initial_margin": 0.00520208,
"interest": 0.05,
"interest_amount": 0,
"leverage": 1,
"result": null,
"created_at": 1568122929782,
"updated_at": 1568122929782,
"orders": [
{
"id": 164993,
"order_type": "limit_order",
"status": "initial",
"market": "XRPBTC",
"side": "sell",
"avg_price": 0,
"total_quantity": 200,
"remaining_quantity": 200,
"price_per_unit": 0.000026,
"timestamp": 1568122929880.75,
"fee": 0.02,
"fee_amount": 0,
"filled_quantity": 0,
"bo_stage": "stage_entry",
"cancelled_quantity": 0,
"stop_price": 0,
}
],
}
]

You can use the id parameter in the response to,

  • Edit Order Details
  • Cancel an Order
  • Retrieve data for an order

To know more about specific endpoints for these, refer to the API Documentation.